﻿
@{

}

<div >
    <div class="flayout_a_box">
        <div class="flayout_a_row">
            <span>充值金额</span>
            <label class="flayout_a_row_right">¥@ViewBag.order.Amount</label>  @*{{Order.Amount}}*@
        </div>
    </div>
    <div class="flayout_a_box">
        <div class="flayout_a_row border_bottom0">
            <span class="flayout_a_row_left gray">支付方式</span>
            <label class="flayout_a_row_right">微信支付</label>
        </div>
    </div>
    <!-- 底部的付款 -->
    <div class="flayout_a_bottomBtnbox">
        <div class="flayout_a_bottomBtnbox_left">
            <span>实付款：</span>
            <label>¥@ViewBag.order.Amount</label>  @*{{Order.Amount}}*@
        </div>
        <a  href="javascript:void(0)" onclick="pay()"><input type="submit" value="付款" class="flayout_a_bottomBtnbox_right"></a>
    </div>
</div>
<script>
    // 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        //公众号支付



    }, false);

    var id =@ViewBag.id;
    

    function pay() {
        layer.load(2);
        $.ajax({
            url: "/OrderPayment/GetRechargeInfo",
            type: "POST",
            dataType: "json",
            async: true,
            data: { id: id },
            success: function (response) {
                layer.closeAll('loading');
                if (response.isSuccess) {
                    var Model = response.data;
                    var Order = response.model;

                    WeixinJSBridge.invoke('getBrandWCPayRequest', {
                        "appId": Model.appId, //公众号名称，由商户传入
                        "timeStamp": Model.timeStamp, //时间戳
                        "nonceStr": Model.nonceStr, //随机串
                        "package": Model.package,//扩展包
                        "signType": "MD5", //微信签名方式:MD5
                        "paySign": Model.paySign //微信签名
                    }, function (res) {
                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                            layer.load(2);
                            var t1 = window.setInterval(getOrderInfo, 1000);
                        }
                        else {

                        }

                    });
                }
                else {
                    layer.msg(response.msg);
                }
            },
            error: function (data) {
                layer.closeAll('loading');
                layer.alert("系统错误！");
            }
        })
    }
    var getOrderInfo = function ()
    {
        $.ajax({
            url: "/OrderPayment/GetMemberRechargeInfo",
            type: "POST",
            dataType: "json",
            async: true,
            data: { id: id },
            success: function (response) {
                layer.closeAll('loading');
                if (response.isSuccess) {
                    layer.closeAll('loading');
                    //$state.go('user.balance');
                    window.location.href="http://wx.youpinsanyue.com/#/user/balance"
                }
                else {
                    layer.msg(response.msg);
                }
            },
            error: function (data) {
                layer.closeAll('loading');
                layer.alert("系统错误！");
            }
        })
    }

    //App.controller('RechargeController', [
    //        '$scope', '$state', '$route', '$http', '$stateParams',
    //            function ($scope, $state, $route, $http, $stateParams) {
    //                layer.load(2);
    //                $http.post("/OrderPayment/GetRechargeInfo", { id: $stateParams.id }).then(function (response) {
    //                    layer.closeAll('loading');
    //                    if (response.data.isSuccess) {
    //                        $scope.Model = angular.copy(response.data.data);
    //                        $scope.Order = angular.copy(response.data.model);
    //                    }
    //                    else {
    //                        layer.msg(response.data.msg);
    //                    }
    //                });


    //                var getOrderInfo = function ()
    //                {
    //                    $http.post("/OrderPayment/GetMemberRechargeInfo", { id: $stateParams.id }).then(function (response) {

    //                        if (response.data.isSuccess) {
    //                            layer.closeAll('loading');
    //                            $state.go('user.balance');
    //                        }

    //                    });
    //                }

    //                $scope.pay = function () {
    //                    WeixinJSBridge.invoke('getBrandWCPayRequest', {
    //                        "appId": $scope.Model.appId, //公众号名称，由商户传入
    //                        "timeStamp": $scope.Model.timeStamp, //时间戳
    //                        "nonceStr": $scope.Model.nonceStr, //随机串
    //                        "package": $scope.Model.package,//扩展包
    //                        "signType": "MD5", //微信签名方式:MD5
    //                        "paySign": $scope.Model.paySign //微信签名
    //                    }, function (res) {
    //                        if (res.err_msg == "get_brand_wcpay_request:ok") {
    //                            layer.load(2);
    //                            var t1 = window.setInterval(getOrderInfo, 1000);

    //                        }
    //                        else {

    //                        }

    //                    });
    //                }
    //            }
    //]);
</script>
